package top.zsyle.system.controller;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.zsyle.basic.util.AjaxResult;
import top.zsyle.basic.util.PageList;
import top.zsyle.system.domain.Log;
import top.zsyle.system.query.LogQuery;
import top.zsyle.system.query.TypeQuery;
import top.zsyle.system.service.LogService;

import javax.management.Query;
import java.util.List;

@RestController
@RequestMapping("/log")
@Api(value = "日志的API",description="日志相关的CRUD功能")
public class LogController {

    @Autowired
    private LogService service;

    @GetMapping
    public List<Log> findAll(){
        return service.findAll();
    }

    @PostMapping
    public PageList<Log> queryPage(@RequestBody LogQuery query){
        return service.queryByPage(query);
    }

    @PutMapping()
    public AjaxResult addOrUpdate(@RequestBody Log log){
        if (log.getId() == null){
            //添加
            service.add(log);
        }else {
            service.update(log);
        }
        return AjaxResult.me().success();
    }

    @DeleteMapping("/{id}")
    public AjaxResult deleteById(@PathVariable Long id){
        service.delete(id);
        return AjaxResult.me().success();
    }

    @PatchMapping
    public AjaxResult batchDelete(@RequestBody List<Long> ids){
        service.batchDelete(ids);
        return AjaxResult.me().success();
    }
}
